<%@ page import="com.wuming.house.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/3/20
  Time: 18:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>管理广告</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css" media="all"/>
</head>
<body style="background-color: #f0f2f5;" class="childrenBody">
<div class="layui-fluid wuli-main">
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>编辑管理</legend>
        </fieldset>
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">广告标题</label>

                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" autocomplete="off"
                               class="layui-input" value="${banner['name']}">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">广告类型</label>

                    <div class="layui-input-inline">
                        <select name="type" id="type">
                            <option value=""></option>
                            <option value="1">一级广告</option>
                            <option value="2">二级广告</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">广告地址</label>

                    <div class="layui-input-inline">
                        <input type="text" id="bannerSource" name="bannerSource" autocomplete="off"
                               class="layui-input" value="${banner['bannerSource']}">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">描述</label>

                    <div class="layui-input-inline">
                        <input type="text" id="summary" name="summary" lay-verify="number"
                               autocomplete="off"
                               class="layui-input" value="${banner['summary']}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">展示图片</label>

                    <div class="layui-upload-list" style="display: inline">
                        <img class="layui-upload-img" id="uploadImage" style="width: 375px;max-height: 150px;min-height: 100px;">
                        <%--<p id="demoText"></p>--%>
                    </div>


                </div>
            </div>
            <input type="hidden" name="id" value="${banner['id']}">
            <input type="hidden" name="picUrl" value="${banner['picUrl']}">
        </form>
        <div class="layui-inline layui-word-aux">
            &nbsp;注意:图片不能超过1Mb
        </div>
        <div class="layui-row wuli-button">
            <button type="button" class="layui-btn" id="btnUploadImg">选择图片</button>
            <button class="layui-btn layui-btn-normal" name="btnSave">保存</button>
        </div>
    </div>
</div>
<script type="text/javascript" src="${allServerPath}static/layui/layui/layui.js"></script>
<script src="${allServerPath}static/js/jquery-2.1.4.min.js"></script>
<script>
    layui.use(['layer', 'form', 'jquery', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.$
            , upload = layui.upload;

        var id = $("input[name='id']").val();
        var picUrl = $("input[name='picUrl']").val();
        if (id != null && id != "") {
            $("#uploadImage").attr("src", ${banner.picUrl});
        }

        //普通图片上传
        var picId = null;
        upload.render({
            elem: '#btnUploadImg'
            , url: '${allServerPath}web/banner/uploadImg.htmls'
            , size : 1024
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#uploadImage').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                if (res.success) {
                    picId = res.data;
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        $("button[name='btnSave']").on('click', function () {
            $.ajax({
                type: "post",
                data: {
                    id: id,
                    name: $("#name").val(),
                    picId: picId,
                    type: $("#type").val(),
                    summary: $("#summary").val(),
                    picUrl: picUrl,
                    bannerSource:$("#bannerSource").val()
                },
                url: '${allServerPath}web/banner/save.htmls',
                success: function (obj) {
                    if (obj.success) {
                        layer.msg("保存成功");
                    }
                }
            });
        });
    });
</script>
</body>
</html>
